/*
 * @FilePath: /tads/server/cmd/app/app.go
 * @Author: wnina0x0
 * @Date: 2025-04-09 14:45:50
 * @Description:
 *
 * 版权信息 : 2025 by wnina0x0, All Rights Reserved.
 */
package app

import (
	"fmt"
	"tads/server/app/business/router"
	"tads/server/global"
	"tads/server/initialize"
)

var (
	Server  string = "server"
	Migrate string = "migrate"
)

type StartRun struct {
	Mode       string
	ConfigMode string
}

func init() {
	initialize.InitConfig()
}

func (s StartRun) Start() error {
	switch s.Mode {
	case Server:
		s.DevMode()
		return nil
	case Migrate:
		s.Migrate()
		return nil
	default:
		global.TADS_LOG.Error("参数错误\n")
		return fmt.Errorf("参数错误")
	}
}

func (s StartRun) DevMode() {
	port := *global.TADS_PORT
	if port == "" {
		router.InitRouter("8000")
	}
	router.InitRouter(port)
	global.TADS_LOG.Info("路由注册成功\n")
}

func (s StartRun) Migrate() {
	initialize.RegisterTable()
	global.TADS_LOG.Info("数据库初始化成功\n")
}
